const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}


function formatStockDate(date) {
    const year = date.getFullYear();
    const month = date.getMonth() + 1; // 0-11 → 1-12
    const day = date.getDate();
    const weekDays = ['日', '一', '二', '三', '四', '五', '六'];
    const week = `星期${weekDays[date.getDay()]}`; // getDay()返回0-6
  
    // 格式示例："2023年10月05日 星期五"
    return `${year}年${month}月${day}日 ${week}`;
  }
  

module.exports = {
  formatStockDate: formatStockDate,
  formatTime
}
